<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改商品描述配置</title>
<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" id="saveAndUpdateFrom" target="_parent" action="">
			<input type="hidden" id="rowId" name="rowId" value='<%=request.getParameter("rowId")%>'/>
			<input type="hidden" id="isReCommit" value="0">
			<input type="hidden" id="token" name="token" value="">
			<input type="hidden" id="gameName" name="gameName" value="">
			<input type="hidden" id="goodsSmallName" name="goodsSmallName" value="">
			<input type="hidden" id="tradeName" name="tradeName" value="">
			<div class="form-group">
				<label class="col-xs-2 text-right">游戏名称:</label>
				<div class="col-xs-3">
					<sk:select cssClass="form-control select" id="gameId" name="gameId" value="" requiredInit="true" ajaxURL="${userInfoV1}/baseGame/gameSelect?wm[DEL_FLAG]=1" onchange="TagUtil.fillOptions('gameId');changeGameQuerySmall(this.value)">
						<option value="">请选择</option>
					</sk:select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">商品小类:</label>
				<div class="col-xs-3">
					<sk:select cssClass="form-control select" id="goodsSmallId" name="goodsSmallId" value="">
						<option id="smallTypeEle" value="">请选择</option>
					</sk:select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">交易类型:</label>
				<div class="col-xs-3">
					<sk:select cssClass="form-control select" id="tradeId" name="tradeId" value="" parentCascadedSelect="gameId" parentParamName="gameId" requiredInit="true" ajaxURL="${tradeV1}/tradeState/gameTradeTypeDictList">
						<option value="">请选择</option>
					</sk:select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">描述内容：</label>
				<div class="col-xs-10">
					<textarea id="content" name="content" style="width:500px;height:150px;border:#ccc solid 1px;text-indent:3px;padding-top:3px;"/></textarea>
				</div>
			</div>
		</sk:form>
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script>
    var configId = $("#rowId").val();//商品描述配置ID
    $(function(){
        //后台登录用户token
        $("#token").val(sessionStorage.getItem("token"));
        //修改商品描述配置时获取数据
        if(configId > 0){
            $.ajax({
                url: "${tradeV1}/tradeBasePublishGoodsDesConfig/getPublishGoodsDesConfigInfo",
                type: "post",
                cache: false,
                data:{"rowId":configId},
                dataType:"json",
                async:false,
                success: function(data) {
                    if (data == null) {
                        return;
                    }
                    $("#gameId").val(data.gameId);
                    $("#gameName").val(data.gameName);
                    TagUtil.fillOptions('gameId');
                    changeGameQuerySmall(data.gameId);
                    $("#goodsSmallId").val(data.goodsSmallId);
                    $("#goodsSmallName").val(data.goodsSmallName);
                    $("#tradeId").val(data.tradeId);
                    $("#tradeName").val(data.tradeName);
                    $("#content").val(data.content);
                }
            });
        }
    });
    var err = {'1':'添加','2':'修改'};
    var action = {'1': '${tradeV1}/tradeBasePublishGoodsDesConfig/save','2': '${tradeV1}/tradeBasePublishGoodsDesConfig/update'};
    function add(){
        var rowId = $('#rowId').val();
        var opera;
        if (!CheckUtil.isNotNull(rowId) || rowId <= 0) {
            opera = 1;//添加
        } else {
            opera = 2;//修改
        }
        var gameId = $("#gameId").val();
        if (!CheckUtil.isNotNull(gameId)) {
            layer.msg("请选择游戏!");
            return;
        }
        var goodsSmallId = $("#goodsSmallId").val();
        if (!CheckUtil.isNotNull(goodsSmallId)) {
            layer.msg("请选择商品小类!");
            return;
        }
        var tradeId = $("#tradeId").val();
        if (!CheckUtil.isNotNull(tradeId)) {
            layer.msg("请选择交易类型!");
            return;
        }
        var content = $("#content").val();
        if (!CheckUtil.isNotNull(content)) {
            layer.msg("描述内容不能为空!");
            return;
        }
        if ($("#isReCommit").val() == 0) {
            $("#isReCommit").val(1);
            //loading层
            var index = layer.load(0, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $("#gameName").val($("#gameId option:selected").text());
            $("#goodsSmallName").val($("#goodsSmallId option:selected").text());
            $("#tradeName").val($("#tradeId option:selected").text());
            $.ajax({
                url: action[opera],
                type: "post",
                cache: false,
                data: new FormData($("#saveAndUpdateFrom")[0]),
                dataType:"json",
                processData: false,
                contentType: false,
                async:false,
                success: function(data) {
                    layer.close(index);
                    if(data.code == 0){
                        parent.layer.msg("添加成功！");
                    } else if(data.code == 1){
                        parent.layer.msg("修改成功！");
                    } else if(data.code == "-2"){
                        parent.window.location.href="${sysManagerV1}/";
                    } else {
                        parent.layer.msg(data.message);
                        $("#isReCommit").val(0);
                    }
                    if(data.code >= 0){
                        parent.findData();
                        parent.layer.close(parent.tableIndex);
                    }
                }
            });
        }
    }

    //下拉列表显示(根据游戏查商品小类)
    function changeGameQuerySmall(gameId) {
        $("#smallTypeEle").siblings().remove();
        if (!CheckUtil.isNotNull(gameId+"")) {
            return false;
        }
        $.ajax({
            type: "post",
            url: "${userInfoV1}/gameGoodsType/smallTypeSelect",
            data:{"wm[GAME_ID]":gameId,"token":sessionStorage.getItem("token")},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data.length<=0) {
                    return;
                }
                var _html = "";
                for (var i=0; i<data.length; i++) {
                    _html += "<option value= '"+data[i].value+"'>"+data[i].label+"</option>";
                }
                $("#smallTypeEle").siblings().remove();
                $("#smallTypeEle").after(_html);
            }
        });
    }
</script>
</html>